from typing import Optional, List, Dict, Any
from pydantic import BaseModel, Field


class TwitterVideoFormat(BaseModel):
    """Twitter视频格式信息"""
    format_id: Optional[str] = Field(None, description="格式ID")
    ext: Optional[str] = Field(None, description="文件扩展名")
    resolution: Optional[str] = Field(None, description="分辨率")
    width: Optional[int] = Field(None, description="视频宽度")
    height: Optional[int] = Field(None, description="视频高度")
    filesize: Optional[int] = Field(None, description="文件大小（字节）")
    filesize_approx: Optional[int] = Field(None, description="估计文件大小（字节）")
    url: Optional[str] = Field(None, description="下载链接")
    quality: Optional[float] = Field(None, description="质量分数")
    format_note: Optional[str] = Field(None, description="格式备注")
    fps: Optional[float] = Field(None, description="帧率")
    vcodec: Optional[str] = Field(None, description="视频编码")
    acodec: Optional[str] = Field(None, description="音频编码")
    tbr: Optional[float] = Field(None, description="总比特率")
    vbr: Optional[float] = Field(None, description="视频比特率")
    abr: Optional[float] = Field(None, description="音频比特率")


class TwitterTweetInfo(BaseModel):
    """Twitter推文基本信息"""
    tweet_id: Optional[str] = Field(None, description="推文ID")
    title: Optional[str] = Field(None, description="推文标题")
    description: Optional[str] = Field(None, description="推文内容")
    uploader: Optional[str] = Field(None, description="发布者名称")
    uploader_id: Optional[str] = Field(None, description="发布者ID")
    uploader_url: Optional[str] = Field(None, description="发布者链接")
    duration: Optional[float] = Field(None, description="视频时长（秒）")
    view_count: Optional[int] = Field(None, description="观看次数")
    like_count: Optional[int] = Field(None, description="点赞数")
    repost_count: Optional[int] = Field(None, description="转发数")
    comment_count: Optional[int] = Field(None, description="评论数")
    upload_date: Optional[str] = Field(None, description="上传日期")
    timestamp: Optional[int] = Field(None, description="时间戳")
    thumbnail: Optional[str] = Field(None, description="缩略图链接")
    webpage_url: Optional[str] = Field(None, description="网页链接")
    is_video: Optional[bool] = Field(None, description="是否为视频")
    width: Optional[int] = Field(None, description="视频宽度")
    height: Optional[int] = Field(None, description="视频高度")
    formats: List[TwitterVideoFormat] = Field(default_factory=list, description="可用视频格式列表")


class TwitterDownloadInfo(BaseModel):
    """Twitter下载信息"""
    tweet_id: Optional[str] = Field(None, description="推文ID")
    title: Optional[str] = Field(None, description="推文标题")
    description: Optional[str] = Field(None, description="推文内容")
    uploader: Optional[str] = Field(None, description="发布者名称")
    uploader_id: Optional[str] = Field(None, description="发布者ID")
    uploader_url: Optional[str] = Field(None, description="发布者链接")
    download_url: str = Field(..., description="视频下载链接")
    format: Optional[str] = Field(None, description="视频格式")
    resolution: Optional[str] = Field(None, description="分辨率")
    width: Optional[int] = Field(None, description="视频宽度")
    height: Optional[int] = Field(None, description="视频高度")
    filesize: Optional[int] = Field(None, description="文件大小（字节）")
    filesize_approx: Optional[int] = Field(None, description="估计文件大小（字节）")
    duration: Optional[float] = Field(None, description="视频时长（秒）")
    thumbnail: Optional[str] = Field(None, description="缩略图链接")
    fps: Optional[float] = Field(None, description="帧率")
    vcodec: Optional[str] = Field(None, description="视频编码")
    acodec: Optional[str] = Field(None, description="音频编码")
    tbr: Optional[float] = Field(None, description="总比特率")
    vbr: Optional[float] = Field(None, description="视频比特率")
    abr: Optional[float] = Field(None, description="音频比特率")
    webpage_url: Optional[str] = Field(None, description="网页链接")
    like_count: Optional[int] = Field(None, description="点赞数")
    view_count: Optional[int] = Field(None, description="观看次数")
    repost_count: Optional[int] = Field(None, description="转发数")
    comment_count: Optional[int] = Field(None, description="评论数")
    timestamp: Optional[int] = Field(None, description="时间戳")
    is_video: Optional[bool] = Field(None, description="是否为视频")


class TwitterQualityUrl(BaseModel):
    """Twitter质量链接信息"""
    url: str = Field(..., description="下载链接")
    format: Optional[str] = Field(None, description="视频格式")
    width: Optional[int] = Field(None, description="视频宽度")
    height: Optional[int] = Field(None, description="视频高度")
    filesize: Optional[int] = Field(None, description="文件大小（字节）")
    filesize_approx: Optional[int] = Field(None, description="估计文件大小（字节）")
    fps: Optional[float] = Field(None, description="帧率")
    vcodec: Optional[str] = Field(None, description="视频编码")
    acodec: Optional[str] = Field(None, description="音频编码")
    tbr: Optional[float] = Field(None, description="总比特率")
    vbr: Optional[float] = Field(None, description="视频比特率")
    abr: Optional[float] = Field(None, description="音频比特率")


class TwitterMultiQualityInfo(BaseModel):
    """Twitter多质量下载信息"""
    tweet_id: Optional[str] = Field(None, description="推文ID")
    title: Optional[str] = Field(None, description="推文标题")
    description: Optional[str] = Field(None, description="推文内容")
    uploader: Optional[str] = Field(None, description="发布者名称")
    uploader_id: Optional[str] = Field(None, description="发布者ID")
    uploader_url: Optional[str] = Field(None, description="发布者链接")
    duration: Optional[float] = Field(None, description="视频时长（秒）")
    thumbnail: Optional[str] = Field(None, description="缩略图链接")
    like_count: Optional[int] = Field(None, description="点赞数")
    view_count: Optional[int] = Field(None, description="观看次数")
    repost_count: Optional[int] = Field(None, description="转发数")
    comment_count: Optional[int] = Field(None, description="评论数")
    timestamp: Optional[int] = Field(None, description="时间戳")
    quality_urls: Dict[str, TwitterQualityUrl] = Field(default_factory=dict, description="各质量下载链接")
    available_qualities: List[str] = Field(default_factory=list, description="可用质量列表")
    is_video: Optional[bool] = Field(None, description="是否为视频")


class TwitterTweetItem(BaseModel):
    """推文列表项"""
    id: Optional[str] = Field(None, description="推文ID")
    title: Optional[str] = Field(None, description="推文标题")
    url: Optional[str] = Field(None, description="推文链接")
    thumbnail: Optional[str] = Field(None, description="缩略图")
    duration: Optional[float] = Field(None, description="时长")
    view_count: Optional[int] = Field(None, description="观看次数")
    like_count: Optional[int] = Field(None, description="点赞数")
    timestamp: Optional[int] = Field(None, description="时间戳")


class TwitterUserTweets(BaseModel):
    """用户推文列表"""
    username: str = Field(..., description="用户名")
    user_id: Optional[str] = Field(None, description="用户ID")
    user_title: Optional[str] = Field(None, description="用户显示名称")
    tweets_count: int = Field(..., description="获取到的推文数量")
    tweets_list: List[TwitterTweetItem] = Field(default_factory=list, description="推文列表")


class TwitterInfoResponse(BaseModel):
    """Twitter信息响应"""
    success: bool = Field(..., description="是否成功")
    data: Optional[TwitterTweetInfo] = Field(None, description="推文信息数据")
    error: Optional[str] = Field(None, description="错误信息")


class TwitterDownloadResponse(BaseModel):
    """Twitter下载响应"""
    success: bool = Field(..., description="是否成功")
    data: Optional[TwitterDownloadInfo] = Field(None, description="下载信息数据")
    error: Optional[str] = Field(None, description="错误信息")


class TwitterMultiQualityResponse(BaseModel):
    """Twitter多质量响应"""
    success: bool = Field(..., description="是否成功")
    data: Optional[TwitterMultiQualityInfo] = Field(None, description="多质量下载数据")
    error: Optional[str] = Field(None, description="错误信息")


class TwitterUserTweetsResponse(BaseModel):
    """Twitter用户推文响应"""
    success: bool = Field(..., description="是否成功")
    data: Optional[TwitterUserTweets] = Field(None, description="用户推文数据")
    error: Optional[str] = Field(None, description="错误信息")


class TwitterQualitiesResponse(BaseModel):
    """Twitter质量选项响应"""
    success: bool = Field(True, description="是否成功")
    qualities: List[str] = Field(default_factory=list, description="支持的质量选项")
    description: str = Field("", description="质量选项说明")


class TwitterUrlTypesResponse(BaseModel):
    """Twitter URL类型响应"""
    success: bool = Field(True, description="是否成功")
    url_types: List[str] = Field(default_factory=list, description="支持的URL类型")
    examples: List[str] = Field(default_factory=list, description="URL示例")
    description: str = Field("", description="URL类型说明") 